package com.xoa.controller.hr;

import com.xoa.dao.users.UsersMapper;
import com.xoa.model.hr.HrTransferWithBLOBs;
import com.xoa.model.users.Users;
import com.xoa.service.hr.HrTransferService;
import com.xoa.service.hr.HrphotoService;
import com.xoa.service.users.impl.UsersServiceImpl;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.dataSource.ContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * @author 左春晖  人事调动控制层
 * @date 2018/7/12 10:02
 * @desc
 */
@Controller
@RequestMapping("/hr/manage")//   /staff_transfer
public class HrTransferController {

    @Resource
    HrTransferService hrTransferService;

    @Resource
    UsersMapper usersMapper;
    /**
     * 添加
     */
    @ResponseBody
    @RequestMapping("/addHrTransfers") // /hr/manage/addHrTransfers
    public ToJson addHrTransfers(HttpServletRequest request, HrTransferWithBLOBs hrTransferWithBLOBs){
        return hrTransferService.addHrTransfer(request,hrTransferWithBLOBs);
    }

    /**
     * 删除   前台传字符串   有传单个也有传多个。
     */
    @ResponseBody
    @RequestMapping("/deleteHrTransfers")// /hr/manage/deleteHrTransfers
    public ToJson deleteHrTransfers(String[] ids){
        return hrTransferService.deleteHrTransfer(ids);
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/upHrTransfers") //  /hr/manage/upHrTransfers
    public ToJson upHrTransfers( HrTransferWithBLOBs hrTransferWithBLOBs){
        return hrTransferService.upHrTransfer(hrTransferWithBLOBs);
    }

    /**
     * 查询  导出
     */
    @ResponseBody
    @RequestMapping(value="/selectHrTransfers", produces = {"application/json;charset=UTF-8"}) //   /hr/manage/selectHrTransfers
    public ToJson<HrTransferWithBLOBs> selectHrTransfers(HttpServletResponse response, HttpServletRequest request , HrTransferWithBLOBs hrTransferWithBLOBs, Integer page, Integer pageSize, boolean useFlag, String export) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
//
        return hrTransferService.selectHrTransfer(response,request,hrTransferWithBLOBs,page,pageSize,useFlag,export);
    }

    /**
     * 根据ID查询
     */
    @ResponseBody
    @RequestMapping("/selectBytransferIds")//   /hr/manage/selectBytransferIds
    public ToJson<HrTransferWithBLOBs> selectBytransferIds(HttpServletRequest request, String transferId) {
        return hrTransferService.selectBytransferId(request,Integer.parseInt(transferId));
    }



        /**
         * 导入
         */
    @ResponseBody
    @RequestMapping("/importsHrTransfers")
    public ToJson<HrTransferWithBLOBs> importsHrTransfers(HttpServletRequest request, HttpServletResponse response, MultipartFile file) {
        return hrTransferService.importsHrTransfer(request,response,file);
    }


    //下拉框获取
    @RequestMapping("/getHrCodess")
    @ResponseBody
    public BaseWrapper getHrCodess(String type) {
        return hrTransferService.getHrCodes(type);
    }






    //主页面
    @RequestMapping("/staff_transfer") //   /hr/manage/staff_transfer
    public String tansferManagement(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrTransfer/HrTransferBar";
    }

    //详情页
    @RequestMapping("/tansferDetail")  //     /hr/manage/tansferDetail
    public String tansferDetail(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrTransfer/HrTransferDetail";
    }

    //导入页
    @RequestMapping("/tansferExport")   //    /hr/manage/tansferExport
    public String tansferExport(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrTransfer/HrTransferImport";
    }

    //管理页面
    @RequestMapping("/tansferManage")   //    /hr/manage/tansferManage
    public String tansferManage(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrTransfer/HrTransferManager";
    }

    //新建页面
    @RequestMapping("/tansferNewedit")   //    /hr/manage//tansferNewedit
    public String tansferNewedit(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrTransfer/HrTransferNew";
    }

    //查询页面
    @RequestMapping("/tansferQuery")   //     /hr/manage//tansferQuery
    public String tansferQuery(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrTransfer/HrTransferQuery";
    }
    //查询页面
    @ResponseBody
    @RequestMapping("/selectOne")   //     /hr/manage//tansferQuery
    public Users selectOne(HttpServletRequest request, String userId) {
        return usersMapper.findUsersByuserId(userId);
    }

    }
